package com.lee.springCloud.serveice.Impl;

import com.lee.springCloud.dao.PaymentDao;
import com.lee.springCloud.domain.CommonResult;
import com.lee.springCloud.domain.Payment;
import com.lee.springCloud.serveice.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Lee
 * @createDate 2021/12/22 14:03
 */
@Service
@Slf4j
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentDao paymentDao;
    @Value("${server.port}")
    private String serverPort;

    @Override
    public CommonResult create(Payment payment) {
        int result = paymentDao.create(payment);
        log.info("*****数据持久化结果："+result);
        if(result > 0){
            return new CommonResult(200,"数据持久化成功！serverPort"+serverPort,result);
        }else {
            return new CommonResult(444,"数据持久化失败！");
        }
    }

    @Override
    public CommonResult getPaymentById(Long id) {
        Payment payment = paymentDao.getPaymentById(id);
        log.info("*****查询结果："+payment);
        if(null != payment){
            return new CommonResult(200,"查询成功！serverPort"+serverPort,payment);
        }else {
            return new CommonResult(444,"查询失败！");
        }
    }

}
